﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SocialMediaProviderBase.cs" company="Catel development team">
//   Copyright (c) 2008 - 2012 Catel development team. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Catwitter.Providers
{
    using System;
    using System.Collections.Generic;
    using Catel;
    using Catel.Data;
    using Models;

    /// <summary>
    /// SocialMediaProviderBase Data object class which fully supports serialization, property changed notifications,
    /// backwards compatibility and error checking.
    /// </summary>
    public abstract class SocialMediaProviderBase : DataObjectBase<SocialMediaProviderBase>, ISocialMediaProvider
    {
        #region Variables
        #endregion

        #region Constructor & destructor
        /// <summary>
        /// Initializes a new object from scratch.
        /// </summary>
        /// <param name="providerName">Name of the provider.</param>
        /// <exception cref="ArgumentException">The <paramref name="providerName"/> is <c>null</c> or whitespace.</exception>
        protected SocialMediaProviderBase(string providerName)
        {
            Argument.IsNotNullOrWhitespace("providerName", providerName);

            Name = providerName;
        }
        #endregion

        #region ISocialMediaProvider Members
        /// <summary>
        /// Gets the name of the provider.
        /// </summary>
        /// <value>The name of the provider.</value>
        public string Name { get; private set; }

        /// <summary>
        /// Gets the last 10 updates from the provider source.
        /// </summary>
        /// <returns>
        /// 	<see cref="IEnumerable{ISocialMediaEntry}"/> containing all the updates.
        /// </returns>
        public abstract IEnumerable<ISocialMediaEntry> GetLast10Updates();
        #endregion

        #region Methods
        /// <summary>
        /// Gets the bitmap from URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns>The <see cref="Bitmap"/> or <c>null</c>.</returns>
        protected Uri GetBitmapFromUrl(string url)
        {
            try
            {
                return new Uri(url);
            }
            catch (Exception)
            {
                return null;
            }

            //try
            //{
            //    WebRequest request = WebRequest.Create(url);
            //    WebResponse response = request.GetResponse();
            //    using (Stream responseStream = response.GetResponseStream())
            //    {
            //        return new Bitmap(responseStream);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Log.Error(ex);
            //    return null;
            //}
        }
        #endregion
    }
}